import java.util.ArrayList;

public class Demo {
    public ArrayList<Integer> demo(ArrayList<Integer> nums1,ArrayList<Integer> nums2){
        Boolean[] bool = new Boolean[1000];
        for (int leg: nums1) {
            bool[leg] = true;
        }
        ArrayList<Integer> ret = new ArrayList<>();
        for (int x:nums2) {
            if (bool[x]){
                ret.add(x);
                bool[x] = false;
            }
        }
        return ret;
    }
}
